package com.CRApp.config;

import com.CRApp.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName: WebConfig
 * @Author : LuoFan洛樊
 * @Date : 2025/2/6 - 12:20
 * Description : TODO
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .excludePathPatterns(
                    "/user/login",         // 登录接口不拦截
                    "/user/register",      // 注册接口不拦截
                    // "/posts/list",         // 推文列表接口不拦截
                    "/posts/postDetails",  // 推文详情接口不拦截
                    "/posts/comments",     // 推文评论接口不拦截
                    "/products/**",        // 商品相关接口不拦截
                    "/essay/list",         // 文章列表不拦截
                    "/essay/search",       // 文章搜索不拦截
                    "/essay/detail"        // 文章详情不拦截
                )
                .addPathPatterns("/**");   // 拦截所有接口
    }
}
